home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / dmalloc.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  87 lines

  1. /*
  2.  * $Id: dmalloc.h,v 0.91 1994/02/20 00:53:35 zhao Pre-Release $
  3.  *
  4.  *. This file is part of BIT shareware package. After the two weeks of
  5.  *  free evaluation period, you are encouraged (required) to register
  6.  *  your copy for a small registration fee, which is $35 for personal use
  7.  *  and $50 for commercial, government and institutional use.
  8.  *
  9.  *  Copyright(c) 1993, 1994 by T.C. Zhao.
  10.  *  All rights reserved.
  11.  *
  12.  *  Permission to use, copy, and distribute this software in its entirety
  13.  *  for non-commercial purposes is hereby granted, provided that the
  14.  *  above shareware and copyright notices and this permission notice
  15.  *  appear in all copies and their documentation.
  16.  *
  17.  *  This software may be modified for your own use, but modified versions
  18.  *  may not be distributed without prior consent of the author.
  19.  *
  20.  *  This software is provided "as is" without expressed or implied
  21.  *  warranty of any kind.
  22.  *
  23.  *.
  24.  *
  25.  * Very simple debug version of malloc family. It works by replacing the
  26.  * standard malloc and its cousins with  my own routines that track, among
  27.  * other things, where mallocs are called and how many bytes they get. All
  28.  * these relies on the the work of true malloc. A true debug version of
  29.  * malloc should replace malloc with calls to sbrk. Anyway, All I want out of
  30.  * this hack is to make sure there are no memory leaks.
  31.  */
  32.  
  33. #ifndef BIT_DMALLOC_H
  34. #define BIT_DMALLOC_H
  35.  
  36. /* malloc from malloc.h is supposedly faster */
  37. #if defined(M_DBG) || !defined(USE_STDLIB_H)
  38.  
  39. #ifdef lint
  40. #include "unistd.h"
  41. #include "ulocks.h"        /* shut up bitching about uptr_s */
  42. #endif
  43. /*
  44.  * include stdlib.h so that all stuff from stdlib will NEVER overwrite things
  45.  * from malloc.h
  46.  */
  47. #include <stdlib.h>
  48. #include <malloc.h>
  49. #else
  50. #include <stdlib.h>
  51. #endif
  52.  
  53. extern void set_mem_warn(int);
  54. extern void mem_stat(void);
  55.  
  56. #ifdef  M_DBG
  57. /* prototypes */
  58. extern void *dbg_malloc(size_t, const char *, int);
  59. extern void *dbg_calloc(size_t, size_t, const char *, int);
  60. extern void *dbg_realloc(void *, size_t, const char *, int);
  61. extern void *dbg_getmat(int, int, size_t, const char *, int);
  62. extern char *dbg_strdup(const char *, const char *, int);
  63. extern void dbg_free(void *, const char *, int);
  64. extern void Tfree(void *);
  65.  
  66. #ifndef M_DBG_OWNER
  67. /* actual replacememnt */
  68. #define malloc(a)        dbg_malloc(a,__FILE__,__LINE__)
  69. #define calloc(a,b)      dbg_calloc(a,b,__FILE__,__LINE__)
  70. #define realloc(a,b)     dbg_realloc(a,b,__FILE__,__LINE__)
  71. #define free(a)          dbg_free(a,__FILE__,__LINE__)
  72. #define strdup(a)        dbg_strdup(a,__FILE__,__LINE__)
  73.  
  74. #ifndef get_mat
  75. #define get_mat(a,b,c)   dbg_getmat(a,b,c,__FILE__,__LINE__)
  76. #endif
  77.  
  78. #endif /* ! M_DMG_OWNER  */
  79.  
  80. #else /* if not debug, tfree becomes free */
  81.  
  82. #define Tfree(p)               free(p)
  83. extern void *get_mat(int, int, size_t);
  84. #endif /* M_DBG */
  85.  
  86. #endif /* _MY_MALLOC_H */
  87.